package olSystem;

import com.spm.pojo.CourseForCjw;
import com.spm.pojo.Grade;
import com.spm.service.impl.GradeServiceImpl;
import com.spm.utils.CFWMapperUtil;
import com.spm.utils.MybatisUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "GradeGetServlet", value = "/GradeGetServlet")
public class GradeGetServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        process(request,response);
    }
    protected void process(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("UTF-8");
        String numSession =  req.getSession().getAttribute("numSession").toString();

        GradeServiceImpl gradeService = new GradeServiceImpl(new MybatisUtils().getSqlSession());
        List<Grade> grades = gradeService.queryForStudent(numSession);


        req.setAttribute("studentCourseList", grades);


        resp.setCharacterEncoding("UTF-8");
        req.getRequestDispatcher("/Olsystem/gradecheck.jsp").forward(req, resp);
    }
}
